home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Codigo / Archivos y secuencias / HtmlDump / HtmlDump.cs next >
Encoding:
Text File  |  2002-06-21  |  1.3 KB  |  50 lines

  1. //---------------------------------------
  2. // HtmlDump.cs ⌐ 2001 by Charles Petzold
  3. //---------------------------------------
  4. using System;
  5. using System.IO;
  6. using System.Net;
  7.  
  8. class HtmlDump
  9. {
  10.      public static int Main(string[] astrArgs)
  11.      {
  12.           if (astrArgs.Length == 0)
  13.           {
  14.                Console.WriteLine("Sintaxis: HtmlDump URI");
  15.                return 1;
  16.           }
  17.  
  18.           WebRequest webreq;
  19.           WebResponse webres;
  20.  
  21.           try
  22.           {
  23.                webreq = WebRequest.Create(astrArgs[0]);
  24.                webres = webreq.GetResponse();
  25.           }
  26.           catch (Exception exc)
  27.           {
  28.                Console.WriteLine("HtmlDump: {0}", exc.Message);
  29.                return 1;
  30.           }
  31.  
  32.           if (webres.ContentType.Substring(0, 4) != "text")
  33.           {
  34.                Console.WriteLine("HtmlDump: URI debe ser un tipo de texto.");
  35.                return 1;
  36.           }
  37.  
  38.           Stream       stream = webres.GetResponseStream();
  39.           StreamReader strrdr = new StreamReader(stream);
  40.           string       strLine;
  41.           int          iLine = 1;
  42.  
  43.           while ((strLine = strrdr.ReadLine()) != null)
  44.                Console.WriteLine("{0:D5}: {1}", iLine++, strLine);
  45.  
  46.           stream.Close();
  47.           return 0;
  48.      }
  49. }
  50.